<?php 

class CategoryAction extends CommonAction{
	
 	public function index(){
        $temp =M('Category')->select();
		$list = cate_tree_list($temp,0);	
		$this->assign("list",$list);
		$this->display();
	}
	
	function add(){
		if(isset($_POST['submit'])){
			$count1 = $_POST['name'];  // 得到分类名的长度
			$count2 = $_POST['path'];
			
			if((strlen($count1) > 0) &&  (strlen($count2) > 0)) {  // 判断字段是否为空
					$data['name'] = $_POST['name'];
					$data['path'] =$_POST['path'];
					$data['jieshao'] =$_POST['jieshao'];
		
					
					if(M('Category')->add($data)){
												 
						$this->success("添加分类成功！",U('index'));
						
					  }
				}else{
					$this->error("添加分类失败,分类名和静态目录不能为空!");
				} 
		}else{
			$cate = M('Category')->select();
			
			$this->display();
		}
		
	}
	
	
	
	
	function edit(){
		  $id = empty($_GET['id'])?exit():$_GET['id'];
		 if(isset($_POST['submit'])){
		 	
			$count1 = $_POST['name'];  // 得到分类名的长度
			$count2 = $_POST['path'];
			
			if((strlen($count1) > 0) &&  (strlen($count2) > 0)) {  // 判断字段是否为空
			
				$data['name'] = $_POST['name'];
				$data['path']=$_POST['path'];
				$data['jieshao'] =$_POST['jieshao'];

				M('Category')->where("id=".$id)->save($data);
				  	 
				$this->success("编辑分类成功！",U('index'));
			
			}else{
				
				$this->error("编辑分类失败,分类名和静态目录不能为空!",U('index'));
				
				}

		 }else{
		 	$cate = M('Category')->select();
			
			$this->li =M('Category')->where("id=".$id)->find();
		 	$this->display();
		 }
		
	}
	
	function del(){
		  $id = empty($_GET['id'])?exit():$_GET['id'];
			  if(isset($id)){
				  M('Category')->where("id=".$id)->delete();
				  $this->success("删除分类成功！",U('index'));
			  }else{
				  $this->error("删除分类成功!",U('index'));
				  }
		 }
}

?>